package controller;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.util.Vector;

import model.Vertrag;
import query.VertragInsertQuery;
import query.VertragSuchenQuery;

/*
 * author squader
 */

public class ControllerVertrag implements Serializable{
	
	private static final long serialVersionUID = -588911383972619474L;

	public static Vector<Vertrag> getVertrag(){
		try{
			//Socket erstellen
			Socket socket = new Socket("20.49.184.100", 5550);
			
			//Outputstream erstellen
			ObjectOutputStream clientOutputStream = new ObjectOutputStream(
					socket.getOutputStream());
			
			//Inputstream erstellen
			ObjectInputStream clientInputStream = new ObjectInputStream(
					socket.getInputStream());
			
			//Controller KundeSuchenQuery erstellen
			VertragSuchenQuery vs = new VertragSuchenQuery();
			
			//Controller Objekt an Server senden
			clientOutputStream.writeObject(vs);
	
			//Antwort von Server erhalten
			Object inputObj = clientInputStream.readObject();
			Vector<Vertrag> vector = (Vector<Vertrag>) inputObj;
			return vector;
		} catch (Exception e){
			
		}
		
		return null;
	}
	
	public static Vertrag insertVertrag(Vertrag vertrag){
		try{
			//Socket erstellen
			Socket socket = new Socket("20.49.184.100", 5550);
			
			//Outputstream erstellen
			ObjectOutputStream clientOutputStream = new ObjectOutputStream(
					socket.getOutputStream());
			
			//Inputstream erstellen
			ObjectInputStream clientInputStream = new ObjectInputStream(socket.getInputStream());
			
			//Controller VertragInsertQuery erstellen
			VertragInsertQuery vi = new VertragInsertQuery(vertrag);
			
			//Controller Objekt an Server senden 
			clientOutputStream.writeObject(vi);
	
			//Antwort von Server erhalten
			Object inputObj = clientInputStream.readObject();
			return (Vertrag) inputObj;
		} catch (Exception e){
			
		}
		return null;
	}
}
